package com.dingwen.treasure.mybatisplus.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dingwen.treasure.base.pojo.vo.PageVo;
import com.dingwen.treasure.model.entity.mybatisplus.SysUser;
import com.dingwen.treasure.mybatisplus.mapper.SysUserMapper;
import com.dingwen.treasure.mybatisplus.service.SysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @author dingwen
 * TODO 使用 Option 优化空指针问题
 * @description 针对表【sys_user(系统用户表)】的数据库操作Service实现
 * @createDate 2022-05-01 20:09:53
 */
@Service
//@DS("slave")
@DS("master")
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
    /**
     * 系统用户映射器
     */
    @Resource
    private SysUserMapper sysUserMapper;


    /**
     * 测试分页查询
     *
     * @param page    页
     * @param deleted 删除
     * @return {@link E}
     */
    @Override
    public <E extends IPage<SysUser>> E testSelectPage(E page, Integer deleted) {
        return sysUserMapper.testSelectPage(page, deleted);
    }

    @Override
    public PageVo<SysUser> optimizeSelectPage(Integer pageNum, Integer pageSize) {
        return PageVo
                .<SysUser>builder()
                .rows(sysUserMapper.optimizeSelectPage(pageNum * pageSize - 1, pageSize))
                // count 执行缓慢
                .totalNum(1L)
                .pageNum(pageNum)
                .pageSize(pageSize)
                .build();
    }
}




